package com.xiaotu.controller;

import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil;
import com.xiaotu.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author zhangxiao
 * @create 2021-10-15 10:16
 */
@CrossOrigin
@RestController
@RequestMapping("battleMatch")
public class BattleMatchController {

    @Autowired
    private RoomService roomService;

    /**
     * 获取房间号
     *
     * @param playerId
     * @return
     */
    @PostMapping("getBattleMode")
    public synchronized Object getBattleMode(Integer playerId) {
        Validator.validateTrue(ObjectUtil.isNotNull(playerId), "playerId 不能为空");
        return roomService.getBattleMode(playerId);
    }

    /**
     * 获取红包陷阱
     *
     * @param roomId
     * @return
     */
    @PostMapping("getRoomRedEnvelopes")
    public Object getRoomRedEnvelopes(Integer roomId) {
        Validator.validateTrue(ObjectUtil.isNotNull(roomId), "roomId 不能为空");
        return roomService.getRoomRedEnvelopes(roomId);
    }

}
